package com.hang.ad.utils;

import com.hang.ad.exceptions.AdException;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang.time.DateUtils;

import java.text.ParseException;
import java.util.Date;

public class CommonUtils {
    private static String[] pattern = {
        "yyyy-MM-dd","yyyy/MM/dd","yyyy.MM.dd"
    };
    public static String md5(String username){
        return DigestUtils.md5Hex(username).toUpperCase();
    }
    public static Date string2Date(String str) throws AdException{
        try {
            return DateUtils.parseDate(str, pattern);
        } catch (ParseException e) {
            throw new AdException(e.getMessage());
        }
    }
}
